//
//  ByCellMyOrderForProduct.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/25.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellMyOrderForProduct.h"

@implementation ByCellMyOrderForProduct

{
    UIImageView *_mainView;             // 主图
    UILabel     *_orderCodeLabel;       // 订单号
    
    UILabel     *_titleLabel;           // 标题
    UILabel     *_currentPriceLabel;    // 当前价格
    UILabel     *_originPriceLabel;     // 原价
    UILabel     *_countTitleLabel;      // 数量标题
    UILabel     *_transferLabel;        // 配送方式
    UILabel     *_realPayLabel;         // 实付
    
    UIView      *_sepLine;              // 内容和功能按钮之间的线条
    
    UIView      *_buttonsView;          //
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupUI];
        [self layout];
        // 模拟
        [self createButtons:0];
    }
    return self;
}

- (void)setupUI {
    
    // 主图
    _mainView = [[UIImageView alloc] init];
    _mainView.backgroundColor = BY_BLUE_COLOR;
    _mainView.layer.cornerRadius = 4;
    _mainView.layer.masksToBounds = true;
    [self.contentView addSubview:_mainView];
    
    // 订单号
    _orderCodeLabel = [UILabel new];
    _orderCodeLabel.adjustsFontSizeToFitWidth = true;
    _orderCodeLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
    _orderCodeLabel.font = FONT(14);
    _orderCodeLabel.textColor = [UIColor whiteColor];
    _orderCodeLabel.text = @"订单号：m123123123";
    [_mainView addSubview:_orderCodeLabel];
    
    // 标题
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.numberOfLines = 2;
    _titleLabel.font = FONT(14);
    _titleLabel.text = @"发了纠纷说多了纠纷说多了纠纷说多了纠纷说多了纠纷说多了纠纷说多了纠纷说多分";
    _titleLabel.textColor = [UIColor blackColor];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_titleLabel];
    
    // 现价
    _currentPriceLabel = [[UILabel alloc] init];
    _currentPriceLabel.adjustsFontSizeToFitWidth = true;
    _currentPriceLabel.font = FONT(18);
    _currentPriceLabel.textColor = BY_RED_COLOR;
    _currentPriceLabel.text = @"￥88888.88";
    _currentPriceLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_currentPriceLabel];
    
    // 原价
    _originPriceLabel = [[UILabel alloc] init];
    _originPriceLabel.adjustsFontSizeToFitWidth = true;
    _originPriceLabel.font = FONT(14);
    _originPriceLabel.textColor = [UIColor lightGrayColor];
    _originPriceLabel.textAlignment = NSTextAlignmentLeft;
    _originPriceLabel.text = @"￥99999.99";
    [self.contentView addSubview:_originPriceLabel];
    
    // 数量标题
    _countTitleLabel = [[UILabel alloc] init];
    _countTitleLabel.font = FONT(14);
    _countTitleLabel.textColor = [UIColor lightGrayColor];
    _countTitleLabel.textAlignment = NSTextAlignmentLeft;
    _countTitleLabel.text = @"购买数量：x1";
    [self.contentView addSubview:_countTitleLabel];
    
    // 配送方式
    _transferLabel = [[UILabel alloc] init];
    _transferLabel.font = FONT(14);
    _transferLabel.textColor = [UIColor lightGrayColor];
    _transferLabel.textAlignment = NSTextAlignmentLeft;
    _transferLabel.text = @"配送方式：自取";
    [self.contentView addSubview:_transferLabel];
    
    // 实付
    _realPayLabel = [[UILabel alloc] init];
    _realPayLabel.font = FONT(14);
    _realPayLabel.textColor = [UIColor blackColor];
    _realPayLabel.textAlignment = NSTextAlignmentRight;
    _realPayLabel.text = @"实付：￥88.88+6.00（运费）";
    [self.contentView addSubview:_realPayLabel];
    
    // 分割
    _sepLine = [[UIView alloc] init];
    _sepLine.backgroundColor = BY_LINE_COLOR;
    [self.contentView addSubview:_sepLine];
    
    //
    _buttonsView = [UIView new];
    [self.contentView addSubview:_buttonsView];

}

- (void)layout {
    
    [_mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@10);
        make.height.equalTo(@140);
        make.width.equalTo(_mainView.mas_height);
    }];
    [_orderCodeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(@0);
        make.height.equalTo(@20);
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_mainView.mas_right).offset(10);
        make.top.equalTo(_mainView);
        make.right.equalTo(@-5);
    }];
    [_currentPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleLabel);
        make.top.equalTo(_titleLabel.mas_bottom).offset(5);
        make.right.equalTo(_originPriceLabel.mas_left).offset(-5);
    }];
    [_originPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_currentPriceLabel);
        make.right.lessThanOrEqualTo(_titleLabel);
    }];
    [_countTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleLabel);
        make.top.equalTo(_currentPriceLabel.mas_bottom).offset(5);
        make.right.equalTo(_titleLabel);
    }];
    [_transferLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_countTitleLabel);
        make.top.equalTo(_countTitleLabel.mas_bottom).offset(5);
    }];
    [_realPayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-10);
        make.bottom.equalTo(_mainView);
    }];
    
    [_sepLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.right.equalTo(@-10);
        make.height.equalTo(@1);
        make.top.equalTo(_mainView.mas_bottom).offset(10);
    }];
    [_buttonsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.height.equalTo(@50);
        make.top.equalTo(_sepLine.mas_bottom);
        make.bottom.equalTo(self.contentView);
    }];
    
}

- (void)createButtons:(NSInteger)index {
    
    [_buttonsView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    
    NSArray *titles = @[@"确认收货", @"查看物流"];
    UIButton *last = nil;
    for (int i = 0; i < titles.count; i ++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.layer.cornerRadius = 15;
        button.layer.borderColor = [UIColor blackColor].CGColor;
        button.layer.borderWidth = 1;
        button.titleLabel.font = FONT(14);
        [button setTitle:titles[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(touchAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [_buttonsView addSubview:button];
        
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(80, 30));
            make.centerY.equalTo(@0);
            if (last) {
                make.right.equalTo(last.mas_left).offset(-10);
            } else {
                make.right.equalTo(@-10);
            }
        }];
        
        last = button;
    }
}

- (void)touchAction:(UIButton *)button {
    
}


@end
